using System;
using System.Web.Mvc;
using RMH.DataAccess.AdoNet;
using RMH.Services;

namespace RMH.Web.Controllers
{
    public class ReportController : ControllerBase
    {

		private IStayService stayService;
		private IRoomService roomService;

		public ReportController(IStayService stayService, IRoomService roomService)
        {
            this.stayService = stayService;
			this.roomService = roomService;
        }

        //
        // GET: /Report/

        [Authorize(Roles = "Administrator")]
        public ActionResult Index()
        {
            return View();
        }

        [Authorize(Roles = "Administrator")]
        public ActionResult LengthOfStay(DateTime? startDate, DateTime? endDate)
        {
            if(!startDate.HasValue)
            {
                startDate = new DateTime(DateTime.Now.Year, 1, 1);
            }
            if (!endDate.HasValue)
            {
                endDate = new DateTime(DateTime.Now.Year, 12, 31);
            }

            ViewData.Model = ReportDataHelper.GetLengthOfStayReport(startDate, endDate);

            return View();
        }

        [Authorize(Roles = "Administrator")]
        public ActionResult OccupancyReport()
        {
			return View();
		}


        [Authorize(Roles = "Administrator")]
        [AcceptVerbs(HttpVerbs.Post)]
		public ActionResult OccupancyReportList(string startDate, string endDate) {
			DateTime start, end;
			try {
				start = DateTime.Parse(startDate);
			}
			catch {
				start = DateTime.Today.AddYears(-1);
			}
			try {
				end = DateTime.Parse(endDate);
			}
			catch {
				end = start.AddYears(1);
			}

			RMH.Entities.OccupancyReportResult model = new RMH.Entities.OccupancyReportResult();

			model.Rooms = roomService.GetAll();
			model.StartDate = start;
			model.EndDate = end;
			model.Stays = stayService.GetByDateRange(start, end);

			return View(model);
		}

    }
}
